added 'split' option to saroute
authorparkrrrr <parkrrrr@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 30 Aug 2005 16:35:50 +0000 (16:35 +0000)
committerparkrrrr <parkrrrr@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 30 Aug 2005 16:35:50 +0000 (16:35 +0000)
gpsbabel/README
gpsbabel/saroute.c

index 8960eefda3ead2a452ca856a0d6324e506c210c5..ab81b3bfd36cad0ea1d750710abc209b2faea88e 100644 (file)
@@ -681,7 +681,12 @@ THE FORMATS
         process will remove the points corresponding to turns only after
         it has removed all other route points.
 
-        Both options only apply to route files from newer versions of 
+        The 'split' option causes GPSBabel to create separate routes for 
+        each street, creating a new route at each turn point.  For obvious
+        reasons, 'split' cannot be used at the same time as the 'turns_only'
+        or 'turns_important' options.
+
+        All options only apply to route files from newer versions of 
         DeLorme software; older versions didn't store the turn information
         with the route.
 
index 2e4d0e0cdeeb7845a725c809ad6fefe46d5230cb..06ccd5cad0b0323cb1bc2cc28ab8bbeb7cc6bae1 100644 (file)
@@ -30,6 +30,7 @@ FILE *infile;
 
 char *turns_important = NULL;
 char *turns_only = NULL;
+char *split = NULL;
 
 static
 arglist_t saroute_args[] = {
@@ -38,6 +39,8 @@ arglist_t saroute_args[] = {
                NULL, ARGTYPE_BOOL },
        {"turns_only", &turns_only, "Only read turns; skip all other points",
                NULL, ARGTYPE_BOOL },
+       {"split", &split, "Split into multiple routes at turns",
+                       NULL, ARGTYPE_BOOL },
        {0, 0, 0, 0 }
 };
 
@@ -80,6 +83,10 @@ static void
 rd_init(const char *fname)
 {
        infile = xfopen(fname, "rb", MYNAME);
+       if ( split && (turns_important || turns_only )) {
+               fatal( MYNAME 
+                     ": turns options are not compatible with split\n" );
+       }
 }
 
 static void
@@ -104,7 +111,8 @@ my_read(void)
                gbint32 lon;
        } *latlon;
        unsigned short coordcount;
-       route_head *track_head;
+       route_head *track_head = NULL;
+       route_head *old_track_head = NULL;
        waypoint *wpt_tmp;
 
        ReadShort(infile);              /* magic */
@@ -207,10 +215,26 @@ my_read(void)
                        route_add_head(track_head);
                }
                while (count) {
+                       old_track_head = NULL;
                        ReadShort(infile);
                        recsize = ReadLong(infile);
                        record = ReadRecord(infile, recsize);
                        stringlen = le_read16((unsigned short *)record);
+                       if ( split && stringlen ) {
+                           if ( track_head->rte_waypt_ct ) {
+                               old_track_head = track_head;
+                               track_head = route_head_alloc();
+                               route_add_head( track_head );
+                           } // end if
+                           if ( !track_head->rte_name ) {
+                               track_head->rte_name = 
+                                       (char *)xmalloc(stringlen+1);
+                               strncpy( track_head->rte_name, 
+                                       record+2, stringlen );
+                               track_head->rte_name[stringlen] = '\0';
+                           } 
+                       }
+                               
                        coordcount = le_read16((unsigned short *)
                                        (record + 2 + stringlen + 0x3c));
                        latlon = (struct ll *)(record + 2 + stringlen + 0x3c + 2);
@@ -238,8 +262,15 @@ my_read(void)
                                        wpt_tmp->route_priority=1;
                                sprintf( wpt_tmp->shortname, "\\%5.5x", 
                                                serial++ );
-                               if ( !turns_only || stringlen ) 
+                               if ( !turns_only || stringlen ) {
                                        route_add_wpt(track_head, wpt_tmp);
+                                       if ( old_track_head ) {
+                                               route_add_wpt(old_track_head,
+                                                  waypt_dupe(wpt_tmp));
+                                               old_track_head = NULL;
+                                       }
+                               }
+                               
        
                                latlon++;
                                coordcount--;